<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>

  <p>目前的经度：  纬度：</p>

  <script>

    var p = document.querySelector("p");
    if("geolocation" in navigator){

      navigator.geolocation.getCurrentPosition(function(position){
        console.log(position);
        var x = position.coords.latitude;
        var y = position.coords.longitude;
        p.innerHTML = "目前的经度：" + x + " 纬度：" + y;
      }),function(err){
        console.log("获取失败~请开启地址定位");
      }

    }else{
      console.log("获取失败~请开启地址定位");
    }

  </script>
</body>
</html>